package main

import . "nc_tools"

/*
 * type ListNode struct{
 *   Val int
 *   Next *ListNode
 * }
 */

/**
 *
 * @param pHead1 ListNode类
 * @param pHead2 ListNode类
 * @return ListNode类
 */
func FindFirstCommonNode(pHead1 *ListNode, pHead2 *ListNode) *ListNode {
	// write code here
	map1 := make(map[*ListNode]int)
	for pHead1 != nil {
		map1[pHead1] = 1
		pHead1 = pHead1.Next
	}
	for pHead2 != nil {
		_, ok := map1[pHead2]
		if ok {
			return pHead2
		}
		pHead2 = pHead2.Next
	}
	return nil
}
